package com.itheima.myreflect2.Student.mapdemo1;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @program: Mymap
 * @description:
 * @author: xuejingjing
 * @create: 2021-06-12 14:08
 **/
public class MyMap1 {
    public static void main(String[] args) {
        //  v put(k key,v value) 添加元素
        // （不仅仅添加，还有覆盖或者替换的功能）
        Map<String,String> map = new HashMap<>();
        map.put("itheima001","小智");
        map.put("itheima002","小关");
        map.put("itheima003","小胖");
        map.put("itheima004","小黑");
        map.put("itheima005", "大师");
        //键不能重复，值可以重复？这种就会覆盖之前相同的key。
        map.put("itheima001","aaa");


        //1.获取所有键的结合
        Set<String> strings = map.keySet();
        System.out.println("======"+strings);
        //这个结果还是无序的。
/*======[itheima003, itheima004, itheima001, itheima002, itheima005]*/

        //2.根据键获取值
        String itheima005 = map.get("itheima005");
        System.out.println("======"+itheima005);


        //3.
        Set<Map.Entry<String, String>> entries = map.entrySet();
        System.out.println("======"+entries);
        //这个结果，和直接sout(map)的结果是一致的。
/*[itheima003=小胖, itheima004=小黑, itheima001=aaa, itheima002=小关, itheima005=大师]*/

        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println("========="+key+","+value);
/*=========itheima003,小胖
=========itheima004,小黑
=========itheima001,aaa
=========itheima002,小关
=========itheima005,大师*/
        }

        method1(map);

    }

    private static void method1(Map<String, String> map) {
        System.out.println(map);
    }
}
